/*                                  ATELIER                                   */

/* %%LICENSE_TAG%%                                                            */
package edu.gmu.view.canvas;

import java.awt.Cursor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.List;

/**
 * LayerMouseMode listens for and handles events 
 * on a AnimatedComponent and re-directs/delegates them to the
 * AnimatedComponent's Layers. 
 */
public class LayerMouseMode extends AbstractMouseMode
{   
    /**
     * Cursor to display when we are in this mode.
     */
    public static final Cursor CURSOR = new Cursor( Cursor.DEFAULT_CURSOR );
    
    /**
     * Name of the MouseMode
     */
    public static final String NAME = "Selection";
    
    /**
     * ImageIcon for this MouseMode
     */
    //public static final ImageIcon ICON = IconUtils.getImageIcon( "Gestures.gif", NAME );
    
    /**
     * Creates a new LayerMouseMode with default values.
     */
    public LayerMouseMode( )
    {
        super( );
    }

    /**
     * Creates a new LayerMouseMode with specified values.
     * 
     * @param canvas
     */
    public LayerMouseMode( Canvas canvas )
    {
        super( canvas );
    }
    
    /**
     * Gets the Cursor for the MouseMode.
     *
     * @return Cursor cursor
     */
    public Cursor getCursor( )
    {
        return CURSOR;
    }
    
    /**
     * Gets the Name of the MouseMode.
     *
     * @return String name
     */
    public String getName( )
    {
        return NAME;
    }
    
    ////////////////////////
    // Mouse Listener events
    ////////////////////////

    /**
     * Invoked when a mouse button has been pressed on the Chart.
     * 
     * @param e MouseEvent
     */
    public void mousePressed(MouseEvent e)
    {
        // Delegate to Layers - top to bottom
        List <Layer> layers = this.canvas.getLayerModel().getLayers();
        for (int i = 0; i < layers.size(); i++)
        {
            Layer layer = layers.get(i);
            if( layer instanceof MouseListener )
            //MouseInputListener listener = layer.getMouseInputListener();
            //if( listener != null )
            {
            	MouseListener listener = (MouseListener)layer;
                listener.mousePressed( e );
            }
        }
    }

    /**
     * Invoked when a mouse button has been released on the Chart.
     * 
     * @param e MouseEvent
     */
    public void mouseReleased(MouseEvent e)
    {
        // Delegate to Layers - top to bottom
        List <Layer> layers = this.canvas.getLayerModel().getLayers();
        for (int i = 0; i < layers.size(); i++)
        {
            Layer layer = layers.get(i);
            if( layer instanceof MouseListener )
            //MouseInputListener listener = layer.getMouseInputListener();
            //if( listener != null )
            {
            	MouseListener listener = (MouseListener)layer;
                listener.mouseReleased( e );
            }
        }
    }

    /**
     * Invoked when the mouse has been clicked on the Chart.
     * 
     * @param e MouseEvent
     */
    public void mouseClicked(MouseEvent e)
    {
        // Delegate to Layers - top to bottom
        List <Layer> layers = this.canvas.getLayerModel().getLayers();
        for (int i = 0; i < layers.size(); i++)
        {
            Layer layer = layers.get(i);
            if( layer instanceof MouseListener )
            //MouseInputListener listener = layer.getMouseInputListener();
            //if( listener != null )
            {
            	MouseListener listener = (MouseListener)layer;
                listener.mouseClicked( e );
            }
        }
    }

    /**
     * Invoked when the mouse enters the Chart.
     * 
     * @param e MouseEvent
     */
    public void mouseEntered(MouseEvent e)
    {
        // Delegate to Layers - top to bottom
        List <Layer> layers = this.canvas.getLayerModel().getLayers();
        for (int i = 0; i < layers.size(); i++)
        {
            Layer layer = layers.get(i);
            if( layer instanceof MouseListener )
            //MouseInputListener listener = layer.getMouseInputListener();
            //if( listener != null )
            {
            	MouseListener listener = (MouseListener)layer;
                listener.mouseEntered( e );
            }
        }
    }

    /**
     * Invoked when the mouse exits the Chart.
     * 
     * @param e MouseEvent
     */
    public void mouseExited(MouseEvent e)
    {
        // Delegate to Layers - top to bottom
        List <Layer> layers = this.canvas.getLayerModel().getLayers();
        for (int i = 0; i < layers.size(); i++)
        {
            Layer layer = layers.get(i);
            if( layer instanceof MouseListener )
            //MouseInputListener listener = layer.getMouseInputListener();
            //if( listener != null )
            {
            	MouseListener listener = (MouseListener)layer;
                listener.mouseExited( e );
            }
        }
    }

    // Mouse Motion Listener events
    ///////////////////////////////

    /**
     * Invoked when a mouse button has been pressed and is moving over the Chart.
     * 
     * @param e MouseEvent
     */
    public void mouseDragged(MouseEvent e)
    {
        // Delegate to Layers - top to bottom
        List <Layer> layers = this.canvas.getLayerModel().getLayers();
        for (int i = 0; i < layers.size(); i++)
        {
            Layer layer = layers.get(i);
            if( layer instanceof MouseMotionListener )
            //MouseInputListener listener = layer.getMouseInputListener();
            //if( listener != null )
            {
            	MouseMotionListener listener = (MouseMotionListener)layer;
                listener.mouseDragged( e );
            }
        }
    }

    /**
     * Invoked when the mouse has been moved over the Chart.
     * 
     * @param e MouseEvent
     */
    public void mouseMoved(MouseEvent e)
    {       
        // Delegate to Layers - top to bottom
        List <Layer> layers = this.canvas.getLayerModel().getLayers();
        for (int i = 0; i < layers.size(); i++)
        {
            Layer layer = layers.get(i);
            if( layer instanceof MouseMotionListener )
            //MouseInputListener listener = layer.getMouseInputListener();
            //if( listener != null )
            {
            	MouseMotionListener listener = (MouseMotionListener)layer;
                listener.mouseMoved( e );
            }
        }
    }
    
}

/*                                  ATELIER                                   */